package com.shengyin.ec.service.payment;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.shengyin.ec.model.dao.payment.PaymentDao;
import com.shengyin.ec.model.entity.Payment;

@Service(value ="paymentService")
public class PaymentServiceImpl implements PaymentService{

	@Autowired
	PaymentDao paymentDao;
	
	
	public List<Payment> getPaymentList(){
		List<Payment> PaymentList = paymentDao.loadAll();
		return PaymentList;
	}


	@Override
	public void createPayment(Payment Payment) {
	      paymentDao.save(Payment);
	}


	@Override
	public void removePaymentById(long id) {
		paymentDao.deleteByKey(id);
	}


	@Override
	public void modifyPayment(Payment payment) {
		
		
		try {
			
			Payment payment1 = paymentDao.get(payment.getId());
			BeanUtils.copyProperties(payment1, payment);
			
			paymentDao.update(payment1);
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (InvocationTargetException e) {
			e.printStackTrace();
		}
	
	}


	@Override
	public Payment getPaymentById(long id) {
		return paymentDao.get(id);	
	}
}
